package iso3.pt.action;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.opensymphony.xwork2.ActionContext;

import iso3.pt.dao.PtDAO;
import iso3.pt.model.Alumno;
import iso3.pt.model.Asignatura;
import iso3.pt.model.Evaluacion;
import iso3.pt.model.Profesor;

public class StudentAction
{
	private int subjectId;
	private Asignatura asignatura;
	private Alumno alumno;
	private Set<Evaluacion> evaluaciones;
	private Set<Asignatura> subjects;

	public Set<Asignatura> getSubjects()
	{
		return subjects;
	}

	public void setSubjects(Set<Asignatura> subjects)
	{
		this.subjects = subjects;
	}

	public int getSubjectId()
	{
		return subjectId;
	}
	
	public void setSubjectId(int id)
	{
		subjectId = id;
	}
	
	
	
	public void setAsignatura(Asignatura asignatura)
	{
		this.asignatura = asignatura;
	}
	
	public Asignatura getAsignatura()
	{
		return asignatura;
	}
	
	
	
  public void setAlumno(Alumno alumno)
  {
  	this.alumno = alumno;
  }
  
  public Alumno getAlumno()
  {
  	return alumno;
  }
  
  
  
	public Set<Evaluacion> getEvaluaciones()
	{
		return evaluaciones;
	}
	
	public void setEvaluaciones(Set<Evaluacion> x)
	{
		this.evaluaciones=x;
	}
	
	
	public String listSubjectMarks()
	{
		Map session = ActionContext.getContext().getSession();
		PtDAO ptdao = PtDAO.getInstance();
		setAlumno((Alumno)session.get("alumno"));
		setAsignatura(ptdao.getAsignatura(getSubjectId()));
		setEvaluaciones(ptdao.getEvaluaciones(getSubjectId(), alumno.getDni()));
		System.out.println(getSubjectId());
		
		return "listSubjectMarks";
	}
	
	public String listAllMarks()
	{
		Map session = ActionContext.getContext().getSession();
		PtDAO ptdao = PtDAO.getInstance();
		setAlumno((Alumno)session.get("alumno"));
		setEvaluaciones(new HashSet(ptdao.getEvaluacionesOrderedByAsignatura(alumno.getDni())));
		
		return "listAllMarks";
	}
	
	public String showEnroll()
	{
		Map session = ActionContext.getContext().getSession();
		PtDAO ptdao = PtDAO.getInstance();
		setAlumno((Alumno)session.get("alumno"));
		setSubjects(ptdao.getAsignaturas());
		
		return "showEnroll";
	}
	
	public String enroll()
	{
		Map session = ActionContext.getContext().getSession();
		PtDAO ptdao = PtDAO.getInstance();
		setAlumno((Alumno)session.get("alumno"));
		getAlumno().addAsignatura(ptdao.getAsignatura(getSubjectId()));
		ptdao.matricular(getAlumno().getDni(), getSubjectId());
		setSubjects(getAlumno().getAsignaturas());
		return "enroll";
	}
	
	public String unenroll()
	{
		Map session = ActionContext.getContext().getSession();
		PtDAO ptdao = PtDAO.getInstance();
		setAlumno((Alumno)session.get("alumno"));
		getAlumno().removeAsignatura(ptdao.getAsignatura(getSubjectId()));
		ptdao.desmatricular(getAlumno().getDni(), getSubjectId());
		setSubjects(getAlumno().getAsignaturas());
		return "unenroll";
	}
}
